import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);

export const constantRoutes = [
	{
		path: "/login",
		name: "Login",
		component: () => import("../views/login/login.vue"),
		meta: {
			title: "登录",
		},
	},
	{
		path: "/",
		name: "Index",
		component: () => import("../views/index/index.vue"),
		meta: {
			title: "首页",
		},
	},
	{
		path: "/question",
		name: "Question",
		component: () => import("../views/question/question.vue"),
		meta: {
			title: "常见问题",
		},
	},
	{
		path: "/document",
		name: "Document",
		component: () => import("../views/document/document.vue"),
		meta: {
			title: "使用手册",
		},
	},
	{
		path: "/searchuser",
		name: "Searchuser",
		component: () => import("../views/search/user.vue"),
		meta: {
			title: "用户搜索",
		},
	},
	{
		path: "/searchgoods",
		name: "Searchgoods",
		component: () => import("../views/search/goods.vue"),
		meta: {
			title: "商品搜索",
		},
	},
	{
		path: "/404",
		name: "404",
		component: () => import("../views/404/404.vue"),
		meta: {
			title: "404",
		},
	},
	{
		path: "*",
		redirect: "/404",
	},
];

const createRouter = () =>
	new Router({
		scrollBehavior: () => ({ y: 0 }),
		routes: constantRoutes,
	});
const router = createRouter();

export function resetRouter() {
	const newRouter = createRouter();
	window.location.reload();
	router.matcher = newRouter.matcher;
}

export default router;
